//
//  MainTabBarController.swift
//  微博项目1
//
//  Created by zhang on 16/5/12.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class MainTabBarController: UITabBarController {
    

    override func viewDidLoad() {
        super.viewDidLoad()
        let compseCallback = { () -> () in
            print("Modal出控制器")
        }
        
        let mainTabBar = CZMainTabBar()
        mainTabBar.composeCallBack = compseCallback
        setValue(mainTabBar, forKey: "tabBar")
        setupChildViewController()
    }
    func setupChildViewController() {
        //首页
        let homeVC = CZHomeViewController()
        addChildViewController(homeVC, title: "首页", imageName: "tabbar_home")
        let messageVC = CZMessageViewController()
        addChildViewController(messageVC, title: "消息", imageName: "tabbar_message_center")
        //设置发现控制器  是是是
        let discoveryVC = CZDiscoveryViewController()
        addChildViewController(discoveryVC, title: "发现", imageName: "tabbar_discover")
        //设置我控制器
        let profileVC = CZProfileViewController()
        addChildViewController(profileVC, title: "我", imageName: "tabbar_profile")
    }
    func addChildViewController(controller: UIViewController,title:String,imageName:String) {
        //设置标题
        controller.title = title
        //设置tabBar图片
        controller.tabBarItem.image = UIImage(named: imageName)
        //设置高亮图片
        controller.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置点击文字颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        //添加给tabBar
        self.addChildViewController(UINavigationController(rootViewController: controller))
        
    }
}
